package com.pig.controller;

import com.pig.pojo.User;
import com.pig.service.UserService;
import com.pig.util.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 需要:完成用户注册入库操作
     * url:/user/doSignUp
     * 返回值:status==200
     */
    @RequestMapping("/doSignUp")
    @ResponseBody
    public SysResult doSignUp(User user){
        /*System.out.println(user.getPhone());
        System.out.println(user.getPassword());
        System.out.println(user.getUsername());*/
        userService.doSaveUser(user);
        return SysResult.success();
    }


    /**需求:检查用户注册名字是否可用
     *url: /user/checkUsername
     */
    @RequestMapping("/checkUsername")
    @ResponseBody
    public SysResult checkUsername(String username){
       int count= userService.checkUsername(username);
       if (count>0){return SysResult.fail();}
        return SysResult.success();
    }


    /**需求:检查用户注册手机号是否可用
     *url: /user/checkPhone
     */
    @RequestMapping("/checkPhone")
    @ResponseBody
    public SysResult checkPhone(String phone){
        System.out.println(phone);
        int count= userService.checkPhone(phone);
        System.out.println(count);
        if (count>0){return SysResult.fail();}
        return SysResult.success();
    }


    @RequestMapping("/item")
    public String doItem(){
        System.out.println("666");
        return "item";
    }

}
